package com.demo.datastructure.reorder.bubbleSort;

/**
 * @description: 冒泡排序实现
 * @author: ljr
 * @time: 2021/5/2 16:19
 */
public class MyBubbleSort2 {

    public static void bubbleSort(int[] args, int n){
         for(int i = 0; i < n; i++){
             boolean flag = true;
             for(int c = 0; c < n-1-i; c++){
                 if(args[c] > args[c+1]){
                     int val = args[c];
                     args[c] = args[c+1];
                     args[c+1] = val;
                     flag = false;
                 }
             }

             if(flag) return;
         }
    }

    public static void main(String[] args) {
        int[] nums = new int[]{4,5,6,3,2,1};
        MyBubbleSort2.bubbleSort(nums,nums.length);
        for(int num : nums){
            System.out.println(num);
        }
    }

}
